﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Threading;

namespace ChatQQ
{
    public partial class ChatForm : Form
    {
        NetworkStream nws;
        TcpClient client;// = DlForm.client;
        string fuid;
        String tuid;
        MainQQForm mf;
        string message;
        public ChatForm(String fuid,String tuid,string message,MainQQForm f)
        {
            this.fuid = fuid;
            this.tuid = tuid;
            this.mf = f;
            this. message = message;
            InitializeComponent();
            client=f.client;
        }

        private void btnclose_Click(object sender, EventArgs e)
        {
            
            this.Close();
        }

        private void ChatForm_Load(object sender, EventArgs e)
        {
            this.Text =mf.myname+ "与"+mf.userni[tuid] + "聊天中";
            rtxbs.Text = message;
            rtxbs.ScrollToCaret();
        }
        
        private void btnsend_Click(object sender, EventArgs e)
        {
            try
            {
                nws = client.GetStream();
                string send = "on" + "|" + fuid + "|" + tuid + "|" + rtxb.Text;//在线
                byte[] chat = Encoding.Default.GetBytes(send.ToCharArray());
                nws.Write(chat,0,chat.Length);
                rtxbs.AppendText("\r\n" + mf.myname + "   " + DateTime.Now + "\r\n" + rtxb.Text);
                rtxb.Text = "";
                rtxb.Focus();
            }
            catch (Exception ex)
            {
                rtxbs.Text += ex.Message;
            }
            
        }

        private void ChatForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            mf.removect(tuid);
        }

        private void rtxb_TextChanged(object sender, EventArgs e)
        {
            rtxb.ScrollToCaret();
        }

        private void rtxbs_TextChanged(object sender, EventArgs e)
        {
            rtxbs.ScrollToCaret();
        }
    }
}